<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${package_dao}.I${pojoName}Dao">
		
	<!-- 展示字段 -->
	<sql id="Base_Column_List">
    	<#list columns as item>  
		t.${item.oldColumnName} AS ${item.columnName}<#if item_index != columns?size - 1>,</#if>
		</#list> 
  	</sql>
  
	<!-- 分页查询公共条件  -->
    <sql id="pageWhere">
		<where>
			<#list columns as item>  
			<if test=" ${item.columnName} != null and ${item.columnName} != '' ">
				AND t.${item.oldColumnName} = ${'#{'}${item.columnName}${'}'}
			</if>
			</#list> 
		</where>
	</sql>
	
	<!-- 分页查询 -->
	<select id="query${pojoName}PageList" parameterType="Map" resultType="${package_pojo}.${pojoName}">
		<include refid="common.Pagination_Head"/>
		select <include refid="Base_Column_List"/>
		from <include refid="common.dbschema"/>${tableName} t
		<include refid="pageWhere"/>
		order by t.id desc
		<include refid="common.Pagination_Tail"/>
	</select>
	
	<!-- 查询 总数-->
	<select id="query${pojoName}PageListCount" parameterType="Map" resultType="int">
		select count(1) from <include refid="common.dbschema"/>${tableName} t
		<include refid="pageWhere"/>
	</select>
	
	<!-- 查询记录不分页 -->
	<select id="query${pojoName}List" parameterType="Map" resultType="${package_pojo}.${pojoName}">
		select <include refid="Base_Column_List"/>
		from <include refid="common.dbschema"/>${tableName} t
		<include refid="pageWhere"/>
		order by t.id desc
	</select>
	
	<!-- 新增记录 -->
	<insert id="insert${pojoName}" parameterType="${package_pojo}.${pojoName}">
		insert into <include refid="common.dbschema"/>${tableName}
		(
		<include refid="Base_Column_List"/>
		)
		values
		(
		<#list columns as item>  
			<#if item.oldColumnName != 'id'>
			${'#{'}${item.columnName}${'}'}<#if item_index != columns?size - 1>,</#if>
			</#if>
		</#list>
		)
	</insert>
	
	<!-- 更新记录 -->
	<update id="update${pojoName}" parameterType="${package_pojo}.${pojoName}">
		update <include refid="common.dbschema"/>${tableName}
		set
			<#list columns as item>  
			<#if item.oldColumnName != 'id'>
			${item.oldColumnName} = ${'#{'}${item.columnName}${'}'}<#if item_index != columns?size - 1>,</#if>
			</#if>
			</#list>
		where id = ${'#{'}id${'}'}
	</update>
	
	<!-- 删除记录 -->
	<delete id="delete${pojoName}" parameterType="${package_pojo}.${pojoName}">
		delete from <include refid="common.dbschema"/>${tableName} 
		where id = ${'#{'}id${'}'}
	</delete>
</mapper>